package com.example.disruptor.demo.disruptor;

import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.WorkHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 保存数据消费者
 * EventHandler和WorkHandler的区别是前者不需要池化，后者需要池化。
 * Created by liunanhua on 2018/7/19.
 */
@Slf4j
public class LongEventSaveConsumer implements EventHandler<LongEvent>, WorkHandler<LongEvent> {

    @Override
    public void onEvent(LongEvent longEvent, long sequence, boolean endOfBatch) {
        this.onEvent(longEvent);
    }

    @Override
    public void onEvent(LongEvent longEvent) {
        long threadId = Thread.currentThread().getId(); // 获取当前线程id
        log.info("消费者[" + threadId +"]消费数据data = " + longEvent.getValue());
    }
}
